<template>
  <div class="balance-tx">
    <div class="cashnote"
         v-if="is_balance_draw == 1">
      <!-- TODO 小程序文字滚动 -->
      <text-marquee v-if="draw_alert && isShowAlert" :marqueeText="draw_alert"></text-marquee>
      <div class="un-balance"
           v-if="userInfo.only_consume_balance>0">
        不可提现{{balance_alias}}：<span style="color: #F30C23">{{mSymbol.name}}{{userInfo.only_consume_balance}}</span>（该部分{{balance_alias}}只能消费不能提现!）
      </div>
    </div>
    <div class="balance-contanier balance-contanier-bg" v-if="!is_hidden_money_dz || (is_hidden_money_dz && userInfo.balance - 0 > 0)">
      <ul class="balance-content clearfix">
        <li>
          <div class="item-balance">
            <p>
              <strong class="fontGilroy">
                <i>{{mSymbol.name}}</i>
                {{userInfo.balance}}
              </strong>
              账户{{balance_alias}}(元)
            </p>
          </div>
        </li>
        <li>
          <div class="blocked">
            <p>
              <strong class="fontGilroy">
                <i>{{mSymbol.name}}</i>
                {{userInfo.frozen_balance}}
              </strong>
              冻结{{balance_alias}}(元)
            </p>
          </div>
        </li>
      </ul>
      <div class="btns">
        <div class="getcash-btn" v-if="!is_weibei_dz && (is_balance_draw == 1 || cashPopData.is_open_enterprise == 1)">
          <button class="cash-apply" @click="verification">我要提现</button>
          <i id="disabled-click"></i>
        </div>
        <div
          class="getcash-btn"
          v-if="cashPopData.is_open_balance_present == 1"
        >
          <button class="cash-apply" @click="clickSendPoint(1)">我要转赠</button>
          <i></i>
        </div>
        <!-- 定制 湖南森磊文化 start -->
        <div
            class="getcash-btn"
            v-if="is_hnslwh_dz"
        >
          <button class="cash-apply" @click="integralChange">同步助农积分</button>
          <i></i>
        </div>
        <!-- 定制 湖南森磊文化 end -->
        <div
                class="getcash-btn"
                v-if="wfx_balance_to_tl"
        >
          <button class="cash-apply" @click="clickTurnBalaceTlClick">转到通联余额</button>
          <i></i>
        </div>
        <!-- 微呗定制 转到微呗 start -->
        <div
          class="getcash-btn"
          v-if="is_weibei_dz"
        >
          <button class="cash-apply" @click="transferWeibeiClick">转到红包</button>
          <i></i>
        </div>
        <!-- 微呗定制 转到微呗 end -->

      </div>
    </div>
    <!--    通联提现  start -->
    <div v-if="!is_hidden_money_dz || (is_hidden_money_dz && cashPopData.tlObj.tl_balance - 0 > 0)">
      <div class="balance-contanier" v-if="cashPopData.tlObj.is_show_tl_balance">
        <ul class="balance-content clearfix balance-content-tl">
          <li>
            <div class="item-balance">
              <p>
                <strong class="fontGilroy">
                  <i>{{mSymbol.name}}</i>
                  {{cashPopData.tlObj.tl_balance}}
                </strong>
                通联余额(元)
              </p>
            </div>
          </li>
        </ul>
        <div class="btns">
          <div class="getcash-btn" v-if="is_tl_balance_draw == 1">
            <button class="cash-apply" @click="verificationTL">我要提现</button>
            <i id="disabled-click"></i>
          </div>
          <div class="getcash-btn" v-if="is_tl_deposit_send == 1">
            <button class="cash-apply" @click="clickSendPoint(2)">我要转赠</button>
            <i id="disabled-click"></i>
          </div>
        </div>
      </div>
    </div>
    <!--  通联提现 end  -->

    <div class="cash-detail">
      <div class="tab-nav" v-if="is_balance_draw == 1 || cashPopData.is_open_enterprise == 1">
        <span :class="type==1?'show':''"
              @click="clickItem(1)">
          提现明细
          <i></i>
        </span>
        <span :class="type==2?'show':''"
              @click="clickItem(2)">
          {{balance_alias}}变动记录
          <i></i>
        </span>
      </div>
      <div class="tab-nav" v-else>
        <span class="show">
          {{balance_alias}}变动记录
          <i></i>
        </span>
      </div>
      <div class="detail-item">
        <tx-log v-if="is_balance_draw == 1 || cashPopData.is_open_enterprise == 1"
                v-show="type==1"
                @cancelTx="cancel"
                ref="txLog"></tx-log>
        <balance-log v-show="type==2" ref="balanceLog"></balance-log>
      </div>
    </div>
    <van-popup v-model="showCashPop"
               position="top"
               :style="{ height: '100%' }">
      <tx-pop @closePop="closeCashPop"
              :dzData="dzData"
              :cashPopData="cashPopData"></tx-pop>
    </van-popup>
    <van-popup v-model="showCashPopTl"
               position="top"
               :style="{ height: '100%' }">
      <txTlPop @closePop="closeCashPop"
               v-if="showCashPopTl"
               :dzData="dzData"
               :cashPopData="cashPopData"></txTlPop>
    </van-popup>
    <!--转赠弹窗-->
    <van-popup
      class="donation-box-pop"
      v-model="showSendDialog"
    >
      <div class="donation-box">
        <div class="title-box">{{balance_alias}}转赠</div>
        <div class="donation-con-box" v-if="!donationSuccess">
          <div class="con-box">
            <div class="input-box clearfix friend-uid-box">
              <label for="">会员ID：</label><input type="number" placeholder="请输入会员ID" name="friend_uid" id="J-get-info" v-model="sendPointFriendUid" @input="changeFriendId"/>
              <div class="btn-verify" @click="clickVerifyFriend">验证</div>
              <span class="info" v-show="friendVerifyInfo.length>0">{{friendVerifyInfo}}</span>
            </div>
            <div class="input-box clearfix friend-info-box">
              <label for="">会员信息：</label>
              <div class="friend-info">
                <span class="avatar">
                  <img :src="avatar" alt="" v-show="avatar">
                </span>
                <span class="nickname">{{nickname || '微信昵称'}}</span>
              </div>
            </div>
            <div class="input-box clearfix amount-box">
              <label for="">转赠金额：</label>
              <!-- TODO 小程序输入小数 -->
              <input type="digit" placeholder="请输入转赠金额" name="point" v-model="sendPointAmount" @input="changeAmount"/>
              <div class="mark">&yen;</div>
              <span class="info" v-show="amountVerify.length>0">{{amountVerify}}</span>
            </div>
            <div class="input-box clearfix friend-uid-box" v-if="give_type == 2">
              <label for="">短信验证：</label>
              <input type="number" placeholder="请输入验证码" name="transferTlBalance_code" class="code-input" v-model="transferTlBalance_code"/>
              <div class="btn-verify code-btn code-btn-send" v-if="isSendCode" @click="handleSendCode">发送</div>
              <div class="btn-verify code-btn count-down-tx" v-else>
                <span class="num">{{count_down}}s后重发</span>
              </div>
            </div>
          </div>
          <div class="btn-box">
            <div class="btn cancel-btn" @click="closeDialog">取消</div>
            <div class="btn confirm-btn" @click="clickConfirmSend">确定</div>
          </div>
        </div>
        <div class="donation-success-box" v-else>
          <div class="con-box">
            <div class="img-box">
              <img src="https://img.wifenxiao.com/h5-wfx/images/success3.png" alt="">
            </div>
            <div class="txt">转赠成功</div>
          </div>
          <div class="btn-box">
            <div class="btn close-btn" @click="closeSucessDialog">关闭</div>
          </div>
        </div>
			</div>
    </van-popup>
    <!-- 提现类型选择 -->
    <div class="withdrawalTypeBox_wrapper" v-show="withdrawalTypeShow">
      <div class="withdrawalTypeBox_block">
        <div class="block_img" @click="withdrawalTypeShow = false">
          <img src="https://img.wifenxiao.com/h5-wfx/images/user/icon_del.png" alt="">
        </div>
        <h6>提现类型</h6>
        <div class="block_selmain">
          <div class="block_selmain_item" v-if="is_balance_draw == 1" @click="clickWithdrawalType(1)" :class="txType == 1 ? 'sel': ''">
            <i class="icon personal"></i>
            <p class="withdrawal_txt">
              <span class="check"></span>
              <span>个人提现</span>
            </p>
          </div>
          <div class="block_selmain_item" @click="clickWithdrawalType(2)" :class="txType == 2 ? 'sel': ''">
            <i class="icon enterprise"></i>
            <p class="withdrawal_txt">
              <span class="check"></span>
              <span>企业提现</span>
            </p>
          </div>
        </div>
        <div class="block_btn">
          <button class="block_btn_next" @click="clickNext()">下一步</button>
        </div>
      </div>
    </div>
    <!-- 余额转通联余额弹窗 start -->
    <main>
      <van-dialog
              v-model="showBalanceTurnBalanceTl"
              title="转到通联余额"
              show-cancel-button
              confirm-button-text="确定"
              class="common-confirm"
              :before-close="balanceTurnBalanceTlClick"
      >
        <div class="pop-inputInfo">
          <input type="number" name="point" placeholder="请输入金额" v-model="balanceTurnBalanceMoneyTl"/>
        </div>
      </van-dialog>
    </main>
    <!-- 余额转通联余额弹窗 end -->
    <!-- 余额转微呗弹窗 start -->
    <main>
    <van-dialog
      v-model="showBalanceTurnWeibei"
      title="转到红包"
      show-cancel-button
      confirm-button-text="确定"
      class="common-confirm"
      :before-close="showBalanceTurnWeibeiClick"
    >
      <div class="pop-inputInfo">
        <input type="number" name="point" placeholder="请输入金额" v-model="balanceTurnBalanceMoneyWeibei"/>
      </div>
    </van-dialog>
    </main>
    <!-- 余额转微呗弹窗 end -->
  </div>
</template>

<script>
import Vue from 'vue'
import { getBalanceTx, cancelTx, transferBalance, getUserBasicInfo, getEnterpriseStatus, setBalanceTurnBalanceTl, signContract } from '@/api/user/member/memberApi'
import { getMQCloud, checkHasQualification } from '@/api/dz/dzApi'
import { validLength } from '@/utils/validate'
import txLog from './txLog/index'
import balanceLog from './balanceLog/index'
import txPop from '@/views/user/components/txPop/index'
import textMarquee from '@/components/textMarquee' // 文字滚动
import { mapGetters } from 'vuex'
import { openPage } from '@/utils/utils'
import { slwhDzSyncPoint } from '@/api/dz/slwhDzApi'
import txTlPop from '@/views/user/components/txTlPop/index'
import { transferTlBalance, submitTransferTlBalance } from '@/api/order/order.js'
import { weiBeiTransferAccount } from '@/api/dz/weibei'
export default Vue.extend({
  name: 'index',
  components: {
    txLog,
    balanceLog,
    txPop,
    textMarquee,
    txTlPop
  },
  data() {
    return {
      showSendDialog: false,
      sendPointForm: {
        friend_uid: '',
        amount: ''
      },
      sendPointFriendUid: '',
      sendPointAmount: '',
      isFriendVerify: 0, // 0没验证，1验证通过，2验证失败
      friendVerifyInfo: '',
      amountVerify: '',
      avatar: '',
      nickname: '',
      donationSuccess: false,
      type: 1, // 1为提现明细、2为余额变动记录
      draw_alert: '',
      is_balance_draw: '', // 是否开启余额提现
      isShowAlert: true,
      userInfo: {
        balance: '',
        frozen_balance: ''
      },
      canClick: true,
      showCashPop: false,
      in_time: null, // 设置提现时间
      show_time_tip: null, // 提现时间提示
      is_draw_int: null, // 提现方式   整额   全额
      // remaining_commission: null,
      withdraw_multiple: null,
      withdraw_start_amount: null,
      code: null,
      txLog: [],
      balanceLog: [],
      cashPopData: {
        is_balance: true, // 弹框判断是余额提现
        is_commission: false, // 弹框判断是佣金提现
        is_supplierWithdraw: false, // 弹框判断是供应商收入
        withdraw_type: [],
        draw_alert: '',
        bankList: null, // 银行列表
        user_behavior_jd: null, // 银行
        user_behavior_wechat: null, // 微信
        user_behavior_alipay: null, // 支付宝
        commssion_to_balance_rate: '',
        withdraw_proportion: '',
        is_qz: null,
        is_draw_int: null, // 提现方式   整额   全额
        withdraw_percentage: '',
        max_tx_money: null,
        min_tx_money: null,
        withdraw_apply_agreement: null,
        need_withdraw_apply_agreement: null,
        remaining_commission: null,
        withdraw_start_amount: null,
        withdraw_multiple: null,
        must_pay_password: null,
        popup_show: null,
        code: null,
        is_open_balance_present: null, // 提现按钮显示开关
        is_id_card: null, // 是否开启需要填写身份证号码和姓名
        id_card_front_back: null, // 是否开启上传身份证正反面
        is_open_enterprise: null, // 是否开启企业提现
        withdraw_need_phone: null, // 是否需要填写手机号
        tlObj: {
          is_show_tl_balance: 0
        },
        withdraw_balance_point_proportion: 0,
        withdraw_point_proportion: 0,
        is_withdraw_point_dz: 0
      },
      dzData: {
        // 云账户
        is_mq_cloud: false,
        cloud_pay_now_type: [],
        cloud_type: null,
        cloud_default_1: null,
        cloud_default_2: null,
        cloud_default_3: null,
        // 薇曼
        is_wm_dz: false
      },
      is_yj_dz: false, // $_yj定制
      // 企业提现
      withdrawalTypeShow: false, // 提现类型选择弹窗
      txType: 1, // 提现类型
      balance_alias: '', // 余额名称别名
      is_hnslwh_dz: 0, // 定制 湖南森磊文化 同步积分
      showCashPopTl: false, // 通联余额提现
      showBalanceTurnBalanceTl: false,
      balanceTurnBalanceMoneyTl: '',
      wfx_balance_to_tl: 0,
      is_hidden_money_dz: 0,
      is_tl_balance_draw: 0, // 是否开启 通联余额提现按钮
      is_tl_deposit_send: 0, // 是否开启 通联余额转赠
      give_type: 1,
      isSendCode: true,
      count_down: 0,
      transferTlBalance_code: '',
      biz_order_no: '',
      resDataD: {},
      // 定制  转到微呗 satrt
      is_weibei_dz: false,
      showBalanceTurnWeibei: false,
      balanceTurnBalanceMoneyWeibei: '',      
      // 定制  转到微呗 end
    }
  },
  watch: {
    isFriendVerify(val) {
      if (val == 0) {
        this.friendVerifyInfo = ''
      } else if (val == 1) {
        this.friendVerifyInfo = '验证完成，请在下方输入金额'
      } else if (val == 2) {
        this.friendVerifyInfo = '您输入的ID有误，请重新输入'
      }
    }
  },
  computed: {
    remaining_commission() {
      return parseFloat(this.userInfo.balance) || 0
    },
    // 获取自定义符号
    ...mapGetters(['mSymbol'])
  },
  methods: {
    // 通联余额转赠 发送验证码
    handleSendCode() {
      if (!validLength(this.sendPointFriendUid)) {
        this.friendVerifyInfo = '请输入会员ID'
        return false
      }
      if (this.isFriendVerify == 0) {
        this.friendVerifyInfo = '请先验证会员ID'
        return false
      } else if (this.isFriendVerify == 2) {
        return false
      }
      if (!validLength(this.sendPointAmount) || this.sendPointAmount <= 0) {
        this.amountVerify = '请输入正确的转赠金额'
        return false
      } else if (parseFloat(this.sendPointAmount) > parseFloat(this.cashPopData.tlObj.tl_balance)) {
        this.amountVerify = '余额不足'
        return false
      }
      this.$loadingWrap.show()
      const sendData = {
        friend_uid: this.sendPointFriendUid,
        amount: this.sendPointAmount
      }
      transferTlBalance(sendData).then(res => {
        this.$loadingWrap.close()
        if (res.status == 1) {
          this.biz_order_no = res.data.biz_order_no
          this.count_down = 60
          this.isSendCode = false
          this.count_downtimer = setInterval(() => {
            this.count_down--
            if (this.count_down <= 0) {
              this.isSendCode = true
              clearInterval(this.count_downtimer)
            }
          }, 1000)
        } else {
          this.$Error(res.msg)
        }
      })
    },
    // 定制 湖南森磊文化 同步积分
    integralChange() {
      slwhDzSyncPoint().then(res => {
        if (res.status == 1) {
          this.$Error(res.data.msg)
          if (res.data.status == 1) {
            this.init()
          }
        } else {
          this.$Error(res.msg)
        }
      })
    },
    init() {
      this.$loadingWrap.show()
      setTimeout(() => {
        this.$loadingWrap.close()
      }, 10000)
      getBalanceTx().then(res => {
        this.$loadingWrap.close()
        if (res.status == 1) {
          // 如果开启云账户 获取云账户数据（功能已下放，不做定制限制）
          if (res.data.is_moon_cloud) {
            this.dzData.is_mq_cloud = true
            this._getMQCloud()
          }
          const resData = res.data

          this.cashPopData.is_withdraw_point_dz = resData.is_withdraw_point_dz || 0
          // console.log('131313asd', resData.is_withdraw_point_dz)
          // is_balance
          this.cashPopData.is_balance = true
          // this.cashPopData.withdraw_point_proportion = resData.withdraw_point_proportion || 0
          this.cashPopData.withdraw_balance_point_proportion = resData.withdraw_balance_point_proportion || 0
          
          this.draw_alert = this.cashPopData.draw_alert = resData.draw_alert
          this.is_balance_draw = resData.is_balance_draw
          this.userInfo = resData.user
          this.balanceLog = resData.balance_change
          this.in_time = resData.in_time
          this.show_time_tip = resData.specify_time
          this.is_draw_int = resData.is_draw_int
          this.code = resData.code
          // this.remaining_commission = this.cashPopData.remaining_commission =
          //   resData.remaining_commission
          this.withdraw_multiple = resData.withdraw_multiple || 0
          this.withdraw_start_amount = resData.withdraw_start_amount || 0
          this.commission_name = resData.commission_name
          this.balance_alias = resData.balance_alias // 余额名称别名
          wx.setNavigationBarTitle({
            title: resData.balance_alias
          })
          this.resDataD = resData
          // 提现弹框
          this.cashPopData.withdraw_type = resData.withdraw_type
          this.cashPopData.bankList = resData.bank_list
          this.cashPopData.user_behavior_jd = resData.user_behavior_jd
          this.cashPopData.user_behavior_wechat = resData.user_behavior_wechat
          this.cashPopData.user_behavior_alipay = resData.user_behavior_alipay
          // this.cashPopData.commssion_to_balance_rate =
          //   resData.commssion_to_balance_rate
          this.cashPopData.withdraw_proportion = resData.withdraw_proportion
          this.cashPopData.is_draw_int = resData.is_draw_int
          this.cashPopData.withdraw_percentage = resData.withdraw_percentage
          this.cashPopData.max_tx_money = resData.max_tx_money
          this.cashPopData.min_tx_money = resData.min_tx_money
          this.cashPopData.is_qz = resData.is_qz
          this.cashPopData.withdraw_apply_agreement =
            resData.withdraw_apply_agreement
          this.cashPopData.need_withdraw_apply_agreement =
            resData.need_withdraw_apply_agreement
          this.cashPopData.remaining_commission = this.remaining_commission
          this.cashPopData.withdraw_multiple = this.withdraw_multiple
          this.cashPopData.withdraw_start_amount = this.withdraw_start_amount
          this.cashPopData.must_pay_password = resData.must_pay_password
          this.cashPopData.popup_show = resData.popup_show
          this.cashPopData.code = resData.code
          // 是否显示提现
          this.cashPopData.is_open_balance_present = resData.is_open_balance_present
          this.cashPopData.is_id_card = resData.is_id_card // 是否开启需要填写身份证号码和姓名
          this.cashPopData.id_card_front_back = resData.id_card_front_back // 是否开启上传身份证正反面
          this.cashPopData.last_withdraw_info = resData.last_withdraw_info
          // 是否开启企业提现
          this.cashPopData.is_open_enterprise = resData.is_open_enterprise
          if (this.is_balance_draw != 1 && this.cashPopData.is_open_enterprise != 1) {
            this.type = 2
          }
          this.cashPopData.withdraw_need_phone = resData.withdraw_need_phone // 是否需要填写手机号
          // 定制 湖南森磊文化 插件是否显示
          this.is_hnslwh_dz = resData.is_hnslwh_dz || 0
          // 是否开启通联账户
          this.cashPopData.tlObj = {}
          this.cashPopData.tlObj.is_show_tl_balance = resData.is_show_tl_balance || 0
          if (this.cashPopData.tlObj.is_show_tl_balance == 1) {
            this.cashPopData.tlObj.txType = 1
            this.cashPopData.tlObj.tlfz_is_opened = 1
            this.cashPopData.tlObj.member_info = resData.member_info
            //  通联账余额
            this.cashPopData.tlObj.tl_balance = resData.user.tl_balance || 0
            // 通联账户余额提现是否需要 签署
            this.cashPopData.tlObj.tlfz_have_person_signed = resData.member_info.tlfz_have_person_signed || 0
          }
          // 是否开启 余额装入通联余额
          this.wfx_balance_to_tl = resData.wfx_balance_to_tl || 0
          // 是否开启 通联余额提现按钮
          this.is_tl_balance_draw = resData.is_tl_balance_draw || 0
          // 是否开启通联余额转赠
          this.is_tl_deposit_send = resData.is_tl_deposit_send || 0
          // 是否开启 通联定制  余额 为0 隐藏 的插件
          this.is_hidden_money_dz = resData.is_hidden_money_dz || 0
          // 定制 转到微呗
          this.is_weibei_dz = resData.is_weibei_dz || 0
        } else {
          this.$Error(res.msg)
        }
      })
    },
    // 切换提现明细和余额变动记录
    clickItem(i) {
      if (i != this.type) {
        this.type = i
      }
    },
    // 关闭体现提示
    closeAlert() {
      this.isShowAlert = false
    },
    // 点击转赠积分
    clickSendPoint(type) {
      this.give_type = type
      if (type == 1) {
        this.balance_alias = this.resDataD.balance_alias
      } else {
        this.balance_alias = '通联余额'
      }
      this.transferTlBalance_code = ''
      this.showSendDialog = true
    },
    // 修改会员ID时将验证，需重新验证
    changeFriendId() {
      this.isFriendVerify = 0
      this.friendVerifyInfo = ''
      this.avatar = ''
      this.nickname = ''
    },
    balanceTurnBalanceTlClick(action, done) {
      if (action == 'confirm') {
        if (!this.balanceTurnBalanceMoneyTl) {
          this.$Error('金额不能为空')
          done(false)
          return false
        } else {
          this.$loadingWrap.show()
          const sendData = {
            amount: this.balanceTurnBalanceMoneyTl
          }
          setBalanceTurnBalanceTl(sendData).then(res => {
            this.$loadingWrap.close()
            if (res.status == 1) {
              this.$Error('操作成功')
              this.balanceTurnBalanceMoneyTl = ''
              done()
              this.init()
            } else {
              this.$Error(res.msg)
              if (res.errorCode == 30008) {
                setTimeout(() => {
                  this.jumpName('tlQualification', { key: 1 })
                }, 1000)
              }
            }
          })
        }
      } else {
        this.balanceTurnBalanceMoneyTl = ''
        done()
      }
    },
    // 余额转到通联余额
    clickTurnBalaceTlClick() {
      this.showBalanceTurnBalanceTl = true
    },
    // 点击验证会员ID
    clickVerifyFriend() {
      if (!validLength(this.sendPointFriendUid)) {
        this.friendVerifyInfo = '请输入会员ID'
        return false
      }
      this.$loadingWrap.show()
      setTimeout(() => {
        this.$loadingWrap.close()
      }, 10000)
      getUserBasicInfo({ user_id: this.sendPointFriendUid }).then(res => {
        this.$loadingWrap.close()
        if (res.status == 1) {
          this.isFriendVerify = 1
          this.avatar = res.data.avatar
          this.nickname = res.data.nickname || ''
        } else {
          // this.$Error(res.msg)
          this.isFriendVerify = 2
        }
      })
    },
    // 改变输入金额时
    changeAmount() {
      this.amountVerify = ''
    },
    // 关闭转赠余额弹窗执行
    closeDialog() {
      this.showSendDialog = false
      setTimeout(() => {
        this.sendPointFriendUid = ''
        this.friendVerifyInfo = ''
        this.sendPointAmount = ''
        this.amountVerify = ''
        this.avatar = ''
        this.nickname = ''
        this.donationSuccess = false
        this.transferTlBalance_code = ''
      }, 500)
    },
    // 点击确定转赠
    clickConfirmSend() {
      if (!validLength(this.sendPointFriendUid)) {
        this.friendVerifyInfo = '请输入会员ID'
        return false
      }
      if (this.isFriendVerify == 0) {
        this.friendVerifyInfo = '请先验证会员ID'
        return false
      } else if (this.isFriendVerify == 2) {
        return false
      }
      if (this.give_type == 1) {
        if (!validLength(this.sendPointAmount) || this.sendPointAmount <= 0) {
          this.amountVerify = '请输入正确的转赠金额'
          return false
        } else if (parseFloat(this.sendPointAmount) > parseFloat(this.userInfo.balance)) {
          this.amountVerify = '余额不足'
          return false
        }
      } else {
        if (!validLength(this.sendPointAmount) || this.sendPointAmount <= 0) {
          this.amountVerify = '请输入正确的转赠金额'
          return false
        } else if (parseFloat(this.sendPointAmount) > parseFloat(this.cashPopData.tlObj.tl_balance)) {
          this.amountVerify = '余额不足'
          return false
        }
      }

      this.$loadingWrap.show()
      setTimeout(() => {
        this.$loadingWrap.close()
      }, 10000)
      // TODO 小程序处理
      // 商城余额 赠送
      if (this.give_type == 1) {
        transferBalance({
          friend_uid: this.sendPointFriendUid,
          amount: this.sendPointAmount
        }).then(res => {
          this.$loadingWrap.close()
          if (res.status == 1) {
            this.donationSuccess = true
          } else {
            this.$Error(res.msg)
          }
        })
      } else {
        //  通联余额赠送
        if (!this.transferTlBalance_code) {
          this.$Error('验证码不能为空')
          this.$loadingWrap.close()
          return false
        }
        const sendData = {
          verification_code: this.transferTlBalance_code,
          biz_order_no: this.biz_order_no,
          friend_uid: this.sendPointFriendUid
        }
        submitTransferTlBalance(sendData).then(res => {
          this.$loadingWrap.close()
          if (res.status == 1) {
            this.donationSuccess = true
          } else {
            this.$Error(res.msg)
          }
        })
      }
    },
    // 转赠成功后关闭弹窗
    closeSucessDialog() {
      this.closeDialog()
      if (this.give_type == 2) {
        setTimeout(() => {
          this.init()
          if (this.$refs.txLog) {
            this.$refs.txLog.init()
          }
          if (this.$refs.balanceLog) {
            this.$refs.balanceLog.init()
          }
        }, 1500)
      } else {
        this.init()
        if (this.$refs.txLog) {
          this.$refs.txLog.init()
        }
        if (this.$refs.balanceLog) {
          this.$refs.balanceLog.init()
        }
      }
    },
    jumpName(name, data) {
      this.$JumpName(this, name, data)
    },
    // 通联我要提现
    verificationTL() {
      // 已经签署
      if (this.cashPopData.tlObj.tlfz_have_person_signed == 1) {
        this.personalWithdrawalTl()
      } else {
        this.jumpName('tlQualification', { key: 1 })
        // // console.log(this.$route.query.key)
      }
    },
    // 通联个人提现
    personalWithdrawalTl() {
      // 设置提现时间判断
      if (this.in_time == 0) {
        this.$Error(this.show_time_tip)
        return false
      }
      // 余额
      // console.log(this.cashPopData.tlObj.tl_balance)
      // console.log(this.withdraw_multiple)
      // console.log(this.withdraw_start_amount)
      if (this.is_draw_int == 1) {
        if (parseFloat(this.cashPopData.tlObj.tl_balance) <= 0) {
          this.$Error(
                  `您的账户余额为0元，不能申请提现！`
          )
          return false
        } else {
          if (this.canClick) {
            this.canClick = false
            setTimeout(() => {
              this.canClick = true
            }, 10000)
            this.showCashPopTl = true
          } else {
            this.$Error('两次操作,请间隔10秒')
          }
        }
      } else {
        if (parseFloat(this.cashPopData.tlObj.tl_balance) <= 0) {
          this.$Error(
                  `您的账户余额为0元，不能申请提现！`
          )
          return false
        } else {
          if (this.canClick) {
            if (this.cashPopData && this.cashPopData.tlObj && this.cashPopData.tlObj.member_info) {
              if (this.cashPopData.tlObj.member_info.contract_status && this.cashPopData.tlObj.member_info.contract_status - 0 != 1) {
                // 通联电子签约未签约,跳去通联签约
                signContract({ member_type: 3 }).then(res => {
                  if (res.status == 1) {
                    const tlfzUrl = res.data.jump_url
                    window.location.href = tlfzUrl
                  } else {
                    this.$Error(res.msg)
                  }
                })
                return false
              }
            }
            this.canClick = false
            setTimeout(() => {
              this.canClick = true
            }, 10000)
            this.showCashPopTl = true
          } else {
            this.$Error('两次操作,请间隔10秒')
          }
        }
      }
    },
    // 我要提现
    verification() {
      // 判断是否开启企业提现
      if (this.cashPopData.is_open_enterprise == 1) {
        if (this.is_balance_draw != 1) {
          this.txType = 2
        }
        this.withdrawalTypeShow = true
      } else {
        this.personalWithdrawal()
      }
    },
    // 提现类型选择
    clickWithdrawalType(type) {
      this.txType = type
    },
    // 下一步
    // 根据状态判断跳转链接
    jumpPath(url, data) {
      this.$JumpPath(this, url, data)
    },
    clickNext() {
      if (this.txType == 1) {
        this.personalWithdrawal()
      } else if (this.txType == 2) {
        this.$loadingWrap.show()
        setTimeout(() => {
          this.$loadingWrap.close()
        }, 10000)
        getEnterpriseStatus().then(res => {
          if (res.status == 1) {
            if (res.data == 0) {
              this.jumpPath('certification', '')
            } else if (res.data == 1) {
              this.jumpPath('certification-reviewing', '')
            } else if (res.data == 2) {
              const data = {
                withdrawType: 'balanceTx',
                code: this.cashPopData.code
              }
              this.jumpPath('certification-review-success', data)
            } else if (res.data == 3) {
              const data = {
                withdrawType: 'balanceTx',
                code: this.cashPopData.code
              }
              this.jumpPath('enterpriseTx-applyCash', data)
            } else if (res.data == 4) {
              this.jumpPath('certification-review-fail', '')
            }
          } else {
            this.$Error(res.msg)
          }
        })
      }
    },
    // 个人提现
    personalWithdrawal() {
      // 如果是云集定制，先判断是否提现认证
      if (this.is_yj_dz) {
        checkHasQualification().then(res => {
          this.$loadingWrap.close()
          if (res.status == 0) {
            this.$Error(res.msg)
            setTimeout(() => {
              openPage(res.url)
            }, 1000)
            return false
          } else {
            // 设置提现时间判断
            if (this.in_time == 0) {
              this.$Error(this.show_time_tip)
              return false
            }
            // 余额

            if (this.is_draw_int == 1) {
              if (this.remaining_commission < +this.withdraw_multiple) {
                this.$Error(
                  `您账户的${this.commission_name}余额不足${this.withdraw_multiple}元，不能申请提现！`
                )
              } else {
                this.showCash()
              }
            } else {
              if (this.remaining_commission < +this.withdraw_start_amount) {
                this.$Error(
                  `您账户的${this.commission_name}余额不足${this.withdraw_start_amount}元，不能申请提现！`
                )
              } else {
                this.showCash()
              }
            }
          }
        })
        return false
      }

      // 设置提现时间判断
      if (this.in_time == 0) {
        this.$Error(this.show_time_tip)
        return false
      }
      // 余额

      if (this.is_draw_int == 1) {
        if (this.remaining_commission < +this.withdraw_multiple) {
          this.$Error(
            `您账户的${this.commission_name}余额不足${this.withdraw_multiple}元，不能申请提现！`
          )
        } else {
          this.showCash()
        }
      } else {
        if (this.remaining_commission < +this.withdraw_start_amount) {
          this.$Error(
            `您账户的${this.commission_name}余额不足${this.withdraw_start_amount}元，不能申请提现！`
          )
        } else {
          this.showCash()
        }
      }
    },
    showCash() {
      if (this.canClick) {
        this.canClick = false
        setTimeout(() => {
          this.canClick = true
        }, 10000)
        this.showCashPop = true
      } else {
        this.$Error('两次操作,请间隔10秒')
      }
    },
    closeCashPop() {
      this.showCashPop = false
      this.showCashPopTl = false
    },
    // 取消提现
    cancel(id) {
      this.$loadingWrap.show()
      setTimeout(() => {
        this.$loadingWrap.close()
      }, 10000)
      const data = {
        id,
        code: this.code
      }
      cancelTx(data).then(res => {
        this.$loadingWrap.close()
        if (res.status == 1) {
          if (res.data.status == 1) {
            this.$Error('操作成功')
            // TODO 小程序 取消提现使用init
              this.$refs.txLog.init()
              this.init()
          } else {
            this.$Error(res.data.msg)
          }
        } else {
          this.$Error(res.msg)
        }
      })
    },
    // 定制   梦泉  start
    _getMQCloud() {
      getMQCloud().then(res => {
        this.$loadingWrap.close()
        if (res.status == 1) {
          this.dzData.cloud_pay_now_type = res.data.cloud_pay_now_type
          this.dzData.cloud_type = res.data.cloud_type
          this.dzData.cloud_default_1 = res.data.cloud_default_1
          this.dzData.cloud_default_2 = res.data.cloud_default_2
          this.dzData.cloud_default_3 = res.data.cloud_default_3
          this.dzData.cloud_agreement = res.data.cloud_agreement
          this.dzData.is_cloud_agreement = res.data.is_cloud_agreement
          this.dzData.agreement_name = res.data.agreement_name
        }
      })
    },
    // 定制   梦泉  end
        // 定制 余额转到微呗start
    transferWeibeiClick() {
      this.showBalanceTurnWeibei = true
    },
    showBalanceTurnWeibeiClick(action, done) {
      if (action == 'confirm') {
        if (!this.balanceTurnBalanceMoneyWeibei) {
          this.$Error('金额不能为空')
          done(false)
          return false
        } else {
          this.$loadingWrap.show()
          const sendData = {
            money: this.balanceTurnBalanceMoneyWeibei,
            type: 1
          }
          weiBeiTransferAccount(sendData).then(res => {
            this.$loadingWrap.close()
            if (res.status == 1) {
              this.$Error('操作成功')
              this.balanceTurnBalanceMoneyWeibei = ''
              done()
              window.location.reload()
            } else {
              this.$Error(res.msg)
              done(false)
            }
          })
        }
      } else {
        this.balanceTurnBalanceMoneyWeibei = ''
        done()
      }
    }
    // 定制 余额转到微呗end
  },
  beforeCreate() {
    // $('body').addClass('bg_white')
    document.getElementsByTagName('body')[0].classList.add('bg_white')
  },
  beforeDestroy() {
      window.$$unsubscribe('txRefreshPage') // 取消关于此消息的所有订阅
  },
  destroyed() {
    // $('body').removeClass('bg_white')
    document.getElementsByTagName('body')[0].classList.remove('bg_white')
  },
  created() {
    this.init()
    const shop = this.$route.query.sid
    const is_yj_dz = this.$_shop('$_yj', shop)
    this.is_yj_dz = is_yj_dz
  },
  mounted() {
        // 小程序触底加载更多
        window.addEventListener('reachbottom', () => {
          if (this.is_balance_draw === 1 && this.type === 1) {
            this.$refs.txLog.onLoad()
          } else if (this.type === 2) {
            this.$refs.balanceLog.onLoad()
          }
        })
        // TODO 订阅刷新提现页面
        window.$$subscribe('txRefreshPage', data => {
          // console.log(data,'refresh')
          this.showCashPop = false
          this.$refs.txLog.init()
          this.$refs.balanceLog.init()
          this.init()
        })
  },
})
</script>
<style lang="scss">
@import "../../../../styles/mixin";
.balance-tx {
  overflow: hidden;
  .cashnote {
    .cashtext {
      width: 750px;
      line-height: 80px;
      box-sizing: border-box;
      padding: 0 30px;
      position: relative;
      display: flex;
      font-size: 26px;
      color: #f38847;
      background: rgba(255, 242, 216, 1);
      p {
        white-space: nowrap;
      }
      span {
        display: block;
        margin-left: 20px;
      }
    }
    .un-balance {
      margin: 20px 30px 0;
      // font-size: 24px;
      color: #666666;
      @include lineClamp(24px, 1, 1);
      height: 24px;
    }
  }
  .balance-contanier {
    width: 700px;
    min-height: 328px;
    background: url("https://img.wifenxiao.com/h5-wfx/images/user/cash_bg.png") center top
      no-repeat #f4f4f4;
    background-size: 100%;
    margin: 25px auto;
    .balance-content {
      padding: 63px 0 41px 0;
      li {
        width: 50%;
        float: left;
        color: #ffd9dd;
        position: relative;
        p {
          font-size: 26px;
          font-weight: 500;
          text-align: center;
        }
        &:first-child {
          &::after {
            content: "";
            height: 80px;
            width: 0;
            border-right: 1px solid #ff7c86;
            position: absolute;
            right: 0;
            top: 50%;
            transform: translateY(-50%);
          }
        }
        strong {
          display: block;
          font-size: 50px;
          margin-bottom: 30px;
          font-weight: normal;
          letter-spacing: 3px;
          max-width: 99%;
          color: #fff;
          @include showEllipsis;
          i {
            display: inline-block;
            font-size: 28px;
            // margin-right: 8px;
          }
        }
      }
    }
    .balance-content-tl{
      display: flex;
      justify-content: center;
      align-items: center;
      li{
        &:first-child {
          &::after {
            content: "";
            height: 80px;
            width: 0;
            border-right: 1px solid transparent !important;
            position: absolute;
            right: 0;
            top: 50%;
            transform: translateY(-50%);
          }
        }
      }
    }
    .btns{
      text-align:center;
    }
    .getcash-btn {
      display: inline-block;
      position: relative;
      // width: 100%;
      height: 60px;
      border-radius: 4px;
      margin: 0 auto;
      text-align: center;
      margin-bottom: 10px;
      .cash-apply {
        width: 190px;
        height: 60px;
        border: 2px solid #fff;
        border-radius: 30px;
        background: transparent;
        font-size: 26px;
        font-weight: 500;
        color: #fff;
        text-align: center;
        line-height: 58px;
      }
    }
  }

  .cash-detail {
    margin: 0 30px;
    .tab-nav {
      // border-bottom: 4px solid #f3f3f3;
      // border-width: 4px;
      display: flex;
      justify-content: space-between;
      span {
        position: relative;
        flex: 1;
        height: 106px;
        line-height: 106px;
        font-size: 32px;
        font-weight: normal;
        text-align: center;
        color: #333333;
        &.show {
          color: #f20b22;
          i {
            display: block;
            position: absolute;
            bottom: -2px;
            left: 50%;
            height: 5px;
            width: 56px;
            border-radius: 3px;
            transform: translateX(-50%);
            background: #f20b22;
          }
        }
      }
    }
  }
  .detail-item {
    margin: 20px 0 0;
    border: 0;
    background: #fff;
    border-radius: 20px;
  }
  .donation-box-pop{
    border-radius:20px;
  }
  .donation-box{
		width: 600px;
    .title-box{
      padding-top: 48px;
      font-size:32px;
      font-weight: normal;
      line-height: 48px;
      text-align: center;
    }
		.con-box{
			position:relative;
			padding:40px 60px;
		}
		.input-box{
			margin:30px 0;
			font-size:28px;
			label{
				float:left;
				display:block;
				width:150px;
				line-height:64px;
				text-align:right;
				font-weight:normal;
				color: #333;
			}
			input{
				position:relative;
				float:left;
				-webkit-appearance: none;
        width:320px;
				height:64px;
				padding:16px 20px;
        font-size:26px;
				border:2px solid #EDEDED;
				border-radius:6px;
			}
      .info{
        display:inline-block;
        font-size:22px;
        color: #999999;
        padding:10px 0 0 150px;
      }
      &.friend-uid-box{
        position:relative;
        input{
          padding-right:100px;
        }
        .btn-verify{
          position:absolute;
          top:0;
          right:10px;
          width:100px;
          height:64px;
          font-size:26px;
          line-height:64px;
          text-align:center;
          color:#fff;
          background: #F30C23;
          border-radius: 2px;
        }
      }
      &.friend-info-box{
        .friend-info{
          display:flex;
          align-items:center;
          line-height:76px;
          .avatar{
            overflow:hidden;
            width:64px;
            height:64px;
            margin-right:10px;
            border-radius:50%;
            background:#ECECEC;
            img{
              display:block;
              width:100%;
            }
          }
          .nickname{
            flex:1;
            font-size:28px;
            font-weight:bold;
            @include showEllipsis;
          }
        }
      }
      &.amount-box{
        position:relative;
        input{
          padding-left:40px;
        }
        .mark{
          position:absolute;
          top:0;
          left:166px;
          line-height:64px;
        }
      }
		}
    .btn-box{
      display:flex;
      border-top:2px solid #ededed;
      .btn{
        width:50%;
        font-size:28px;
        line-height:94px;
        text-align:center;
        color:#333;
        &.confirm-btn{
          border-left:2px solid #ededed;
          color:#f20b22;
        }
      }
    }
    .donation-success-box{
      .img-box{
        width:104px;
        height:104px;
        margin:20px auto;
        img{
          display:block;
          width:100%;
        }
      }
      .txt{
        margin:20px 0 40px;
        font-size:36px;
        line-height: 50px;
        text-align:center;
      }
      .btn-box{
        .close-btn{
          width:100%;
        }
      }
    }
  }
  // 提现类型弹层
  .withdrawalTypeBox_wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 100;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    .withdrawalTypeBox_block {
      position: relative;
      min-width: 600px;
      padding: 54px 70px;
      border-radius: 20px;
      background-color: #fff;
      .block_img{
        position: absolute;
        top: 30px;
        right: 30px;
        width: 28px;
        height: 28px;
        >img{
          max-width: 100%;
          width: 100%;
        }
      }
      h6{
        font-weight:bold;
        font-size:32px;
        color:#333;
        width: 100%;
        text-align: center;
        margin-bottom: 58px;
      }
      .block_selmain{
        display: flex;
        justify-content: space-around;
        margin-bottom: 60px;
        &_item{
          width:186px;
          height:186px;
          background-color:#F5F5F5;
          border: 1px solid #f5f5f5;
          border-radius:10px;
          margin-right: 54px;
          &:last-child{
            margin-right: 0;
          }
          i.icon{
            display: block;
            width: 65px;
            height: 65px;
            margin: 38px auto 18px;
            background-repeat: no-repeat;
            background-position: center;
            background-size: cover;
            &.personal{
              background-image: url("https://img.wifenxiao.com/h5-wfx/images/user/typeIcon.png");
            }
            &.enterprise{
              background-image: url("https://img.wifenxiao.com/h5-wfx/images/user/typeIcon1.png");
            }
          }
          .withdrawal_txt{
            display: flex;
            justify-content: center;
            align-items: center;
            >span{
              display: inline-block;
              font-size: 26px;
              color: #666;
              height: 26px;
            }
            .check{
              position: relative;
              width: 26px;
              height: 26px;
              margin-right: 10px;
              border: 1px solid #b3b3b3;
              border-radius: 50%;
            }
          }
          &.sel{
            border-color: #F10A1D;
            background-color:#FFF7F7;
            i.icon{
              &.personal{
                background-image: url("https://img.wifenxiao.com/h5-wfx/images/user/typeIcon_sel.png");
              }
              &.enterprise{
                background-image: url("https://img.wifenxiao.com/h5-wfx/images/user/typeIcon1_sel.png");
              }
            }
            .withdrawal_txt{
              >span{
                color: #EF0919;
              }
              .check{
                border-color: transparent;
                &::after{
                  content: '';
                  position: absolute;
                  right: 0;
                  bottom: 0;
                  display: block;
                  width: 26px;
                  height: 26px;
                  background: url("https://img.wifenxiao.com/h5-wfx/images/user/icon_check.png") no-repeat center/contain;
                }
              }
            }
          }
        }
      }
      .block_btn_next{
        font-size: 28px;
        color: #fff;
        width: 100%;
        height: 86px;
        line-height: 86px;
        text-align: center;
        background: linear-gradient(to right,#FE1B49, #E90104);
        border-radius: 42px;
      }
    }
  }
}
.balance-contanier-bg{
  background-size: 100% 100% !important;
}
  main{
    .pop-inputInfo {
      width:426px;
      margin: 40px auto;
      input {
        width: 100%;
        height:86px;
        background:rgba(255,255,255,1);
        border:2px solid rgba(237, 237, 237, 1);
        border-radius:6px;
        padding-left: 30px;
        font-size: 24px;
      }
    }
    .pop {
      width: 675px;
      border-radius: 20px;
      &-title {
        border-bottom: 1px solid #ccc;
        margin-bottom: 20px;
        font-size: 32px;
        padding: 20px 40px;
        color: #000;
        display: flex;
        justify-content: space-between;
        align-items: center;
        i {
          display: block;
          width: 40px;
          height: 40px;
          background: url('https://img.wifenxiao.com/h5-wfx/images/user/icon_del.png') center
          no-repeat;
          background-size: 100% 100%;
        }
      }

      button {
        // padding: 20px 20px;
        display: block;
        width: 600px;
        height: 80px;
        line-height: 80px;
        text-align: center;
        background-color: #ff8f09;
        color: #fff;
        border-radius: 80px;
        outline: none;
        border: none;
        // margin: 0px auto;
        margin: 30px auto;
        font-size: 28px;
        text-align: center;
        // box-sizing: border-box
      }
    }
  }
.code-input{
  padding-right: 140px !important;
}
.code-btn{
  width: 140px !important;
  right: 0 !important;
  font-size: 24px !important;
  border-radius: 10px !important;
  height: 50px !important;
  line-height: 50px !important;
  top: 5px !important;
  background: #ECECEC !important;
}
.code-btn-send{
  background: #F30C23 !important;
}
.count-down-tx {
  .num {
    color: #686868;
  }
}
</style>
